<template>
  <div class="app-container">
    <el-form :model="queryParams"
             ref="queryForm"
             size="small"
             :inline="true"
             v-show="showSearch"
             label-width="68px">

      <el-row>

        <el-col :span="6">
          <el-form-item label="提现编号"
                        label-width="80px">
            <el-input v-model="queryParams.withdrawalNo"
                      placeholder="请输入提现编号"
                      clearable
                      @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="支付宝账号"
                        label-width="100px">
            <el-input v-model="queryParams.alipayAccount"
                      placeholder="请输入支付宝账号"
                      clearable
                      @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="申请人姓名"
                        label-width="100px">
            <el-input v-model="queryParams.accountHolder"
                      placeholder="请输入申请人姓名"
                      clearable
                      @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="手机号码"
                        label-width="80px">
            <el-input v-model="queryParams.phone"
                      placeholder="请输入手机号码"
                      clearable
                      @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>

        <el-col :span="6">
          <el-form-item label="审核时间"
                        label-width="80px">
            <el-date-picker clearable
                            v-model="queryParams.checkTime"
                            type="date"
                            value-format="yyyy-MM-dd"
                            placeholder="请选择审核时间">
            </el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :span="6">
          <el-form-item label="审核状态"
                        label-width="100px">
            <el-select v-model="queryParams.status"
                       placeholder="审核状态"
                       clearable>
              <el-option v-for="dict in dict.type.sys_check_status"
                         :key="dict.value"
                         :label="dict.label"
                         :value="dict.value" />
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="8">
          <el-form-item>
            <el-button type="primary"
                       icon="el-icon-search"
                       size="mini"
                       @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh"
                       size="mini"
                       @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10"
            class="mb8">
      <el-col :span="1.5">
        <el-button type="warning"
                   plain
                   icon="el-icon-download"
                   size="mini"
                   @click="handleExport"
                   v-hasPermi="['finance:withdrawal:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch"
                     @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading"
              :data="withdrawalList"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection"
                       width="55"
                       align="center" />
      <el-table-column label="提现编号"
                       align="center"
                       prop="withdrawalNo" />
      <el-table-column label="店铺名称"
                       align="center"
                       prop="shop.shopName" />
      <el-table-column label="支付宝账号"
                       align="center"
                       prop="alipayAccount" />
      <el-table-column label="申请人姓名"
                       align="center"
                       prop="accountHolder" />
      <el-table-column label="手机号码"
                       align="center"
                       prop="phone" />
      <el-table-column label="提现金额"
                       align="center"
                       prop="amount" />
      <el-table-column label="审核状态"
                       align="center">

        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_check_status"
                    :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="审核人"
                       align="center"
                       prop="checkerId" />
      <el-table-column label="审核时间"
                       align="center"
                       prop="checkTime"
                       width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="打款时间"
                       align="center"
                       prop="paymentTime"
                       width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.paymentTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作"
                       align="center"
                       class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status === 2"
                     size="mini"
                     type="text"
                     icon="el-icon-edit"
                     @click="handleCheck(scope.row)">审核</el-button>
          <el-button v-else
                     size="mini"
                     type="text"
                     icon="el-icon-set-up"
                     @click="handleDetail(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList" />

    <!-- 审核提现记录对话框 -->
    <el-dialog :title="title"
               :visible.sync="open"
               width="800px"
               append-to-body>
      <el-form ref="form"
               :model="form"
               :rules="rules"
               label-width="120px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="提现编号"
                          prop="withdrawalNo">
              <el-input v-model="form.withdrawalNo"
                        disabled />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="支付宝账号"
                          prop="alipayAccount">
              <el-input v-model="form.alipayAccount"
                        disabled />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="申请人姓名"
                          prop="accountHolder">
              <el-input v-model="form.accountHolder"
                        disabled />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="身份证号"
                          prop="idCardNo">
              <el-input v-model="form.idCardNo"
                        disabled />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="身份证正面照">
              <el-image v-if="form.idCardFrontUrl"
                        :src="form.idCardFrontUrl"
                        style="width: 200px; height: 200px"
                        fit="cover"
                        :preview-src-list="[form.idCardFrontUrl]" />
              <span v-else>暂无上传</span>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="身份证反面照">
              <el-image v-if="form.idCardBackUrl"
                        :src="form.idCardBackUrl"
                        style="width: 200px; height: 200px"
                        fit="cover"
                        :preview-src-list="[form.idCardBackUrl]" />
              <span v-else>暂无上传</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer"
           class="dialog-footer">
        <el-button type="primary"
                   @click="passHandle">通 过</el-button>
        <el-button type="danger"
                   @click="rejectHandle">驳 回</el-button>
      </div>
    </el-dialog>

    <el-dialog title="审核详情"
               :visible.sync="openDetail"
               width="800px"
               append-to-body>
      <el-form :model="form"
               label-width="120px">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="提现编号">
              <el-input v-model="form.withdrawalNo"
                        disabled />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="支付宝账号">
              <el-input v-model="form.alipayAccount"
                        disabled />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="申请人姓名">
              <el-input v-model="form.accountHolder"
                        disabled />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="身份证号">
              <el-input v-model="form.idCardNo"
                        disabled />
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="驳回原因">
              <el-input v-model="form.rejectReason"
                        type="textarea"
                        disabled />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="身份证正面照">
              <el-image v-if="form.idCardFrontUrl"
                        :src="form.idCardFrontUrl"
                        style="width: 100%;max-height:200px;"
                        fit="cover" />
              <span v-else>暂无上传</span>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="身份证反面照">
              <el-image v-if="form.idCardBackUrl"
                        :src="form.idCardBackUrl"
                        style="width: 100%;max-height:200px;"
                        fit="cover" />
              <span v-else>暂无上传</span>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { listWithdrawal, getWithdrawal, updateWithdrawal } from "@/api/finance/withdrawal"

export default {
  name: "Withdrawal",
  dicts: ['sys_check_status'],
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 提现记录表格数据
      withdrawalList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 审核记录详情页
      openDetail: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        withdrawalNo: null,
        shopId: null,
        accountType: null,
        alipayAccount: null,
        accountHolder: null,
        idCardNo: null,
        idCardFront: null,
        idCardBack: null,
        phone: null,
        amount: null,
        status: null,
        rejectReason: null,
        checkerId: null,
        checkTime: null,
        paymentTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        withdrawalNo: [
          { required: true, message: "提现编号(唯一)不能为空", trigger: "blur" }
        ],
        shopId: [
          { required: true, message: "店铺ID不能为空", trigger: "blur" }
        ],
        accountType: [
          { required: true, message: "账户类型(1:支付宝,2:银行卡)不能为空", trigger: "change" }
        ],
        accountHolder: [
          { required: true, message: "申请人姓名不能为空", trigger: "blur" }
        ],
        phone: [
          { required: true, message: "手机号码不能为空", trigger: "blur" }
        ],
        amount: [
          { required: true, message: "提现金额不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "状态(0:已驳回,1:已通过,2:待审核,3:打款中,4:已到账)不能为空", trigger: "change" }
        ],
        createTime: [
          { required: true, message: "申请时间不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created () {
    this.getList()
  },
  methods: {
    /** 查看审核详情 */
    handleDetail (row) {
      this.reset()
      const id = row.id || this.ids
      getWithdrawal(id).then(response => {

		console.log("数据",response.data);

        this.form = response.data;
		
		
        this.openDetail = true
      })
    },
    /** 驳回 */
    rejectHandle () {
      const data = {
        id: this.form.id,
        status: 0,
		checkerId: this.$store.state.user.nickName
      }
      updateWithdrawal(data).then(res => {
        if (res.code == 200) {
          this.$message.success("申请驳回!");
          this.getList();
        }
		this.open = false;
      })
    },
    /** 查询提现记录列表 */
    getList () {
      this.loading = true
      listWithdrawal(this.queryParams).then(response => {

        this.withdrawalList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel () {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset () {
      this.form = {
        id: null,
        withdrawalNo: null,
        shopId: null,
        accountType: null,
        alipayAccount: null,
        accountHolder: null,
        idCardNo: null,
        idCardFront: null,
        idCardBack: null,
        phone: null,
        amount: null,
        status: null,
        rejectReason: null,
        checkerId: null,
        checkTime: null,
        paymentTime: null,
        createTime: null,
        updateTime: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 审核按钮操作 */
    handleCheck (row) {
      this.reset()
      const id = row.id || this.ids
      getWithdrawal(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "提现审核"
      })
    },
    /** 通过按钮 */
    passHandle () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWithdrawal(this.form).then(response => {
              this.$modal.msgSuccess("操作成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 驳回按钮 */
    passHandle () {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateWithdrawal(this.form).then(response => {
              this.$modal.msgSuccess("操作成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },

    /** 导出按钮操作 */
    handleExport () {
      this.download('finance/withdrawal/export', {
        ...this.queryParams
      }, `withdrawal_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style scoped>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  width: 200px;
  height: 200px;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 200px;
  height: 200px;
  line-height: 200px;
  text-align: center;
}
.avatar {
  width: 200px;
  height: 200px;
  display: block;
}
</style>
